package com.gagakuai.executor;


import com.gagakuai.cache.CacheKey;
import com.gagakuai.cursor.Cursor;
import com.gagakuai.mapping.BoundSql;
import com.gagakuai.mapping.MappedStatement;
import com.gagakuai.session.ResultHandler;
import com.gagakuai.session.RowBounds;
import com.gagakuai.transcation.Transaction;

import java.sql.SQLException;
import java.util.List;

/*
 * @Author houhong
 * @Description 执行sql的地方
 * @Date 12:17 上午 2023/6/29
 * @return {@link null}
 */
public interface Executor {


    ResultHandler NO_RESULT_HANDLER = null;

    /*
     * @param parameter:参数
     * @param mp           ： xml方法的映射
     * @return {@link int}
     * @Author houhong
     * @Description 执行sql
     * @Date 11:36 下午 2023/6/30
     */
    int update(MappedStatement mp, Object parameter) throws SQLException;

    /*
     * @param parameter:参数
     * @param rowBounds:分页？
     * @param resultHandler：结果处理器
     * @param boundSql:对使用者写的映射
     * @param ms:对xml方法的映射
     * @return {@link E}
     * @Author houhong
     * @Description  查询
     * @Date 11:40 下午 2023/6/30
     */
    <E> E query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey cacheKey, BoundSql boundSql) throws SQLException;

    <E> E query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException;

    <E> Cursor<E> queryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds) throws SQLException;

    List<BatchResult> flushStatements() throws SQLException;


    void commit(boolean required) throws SQLException;

    void rollback(boolean required) throws SQLException;

    /*
     * 获取事务
     */
    Transaction getTransaction();

    void close(boolean forceRollback);

    boolean isClosed();

    void setExecutorWrapper(Executor executor);

}
